package com.yhz.openapi.services.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.util.StringUtil;
import com.yhz.openapi.common.ResultTable;
import com.yhz.openapi.dao.AdminUserMapper;
import com.yhz.openapi.entity.AdminUser;
import com.yhz.openapi.services.AdminUserServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminUserServicesImpl implements AdminUserServices {

    @Autowired
    private AdminUserMapper userMapper;

    @Override
    public AdminUser getUserByEmail(String email) {
        if (StringUtil.isNotEmpty(email)) {
            AdminUser userByEmail = userMapper.getUserByEmail(email);
            if (userByEmail == null) {
                return userByEmail;
            }
        }
        return null;
    }

    @Override
    public AdminUser doLogin(String email, String password) {
        if (StringUtil.isNotEmpty(email)&&StringUtil.isNotEmpty(password)) {
            AdminUser user = userMapper.getUserByEmail(email);
            if (user!=null&&user.getPassword().equals(password)) {
                return user;
            }
        }
        return null;
    }

    @Override
    public ResultTable table(Integer page, Integer limit, String realName, String email, Integer status) {
        PageHelper.startPage(page,limit);
        List<AdminUser> users= userMapper.table(realName,email,status);
        PageInfo pi=new PageInfo(users);

        return new ResultTable(0,"msg",(int)pi.getTotal(),pi.getList());
    }
}
